package server;

import static constant.Constant.PORT;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;

import service.Service;

public class Server {
	public Server() throws IOException {
		ServerSocket serviceServer = new ServerSocket(PORT);
		System.out.println("Serveur started");
		while (true) {
			Socket clientSocket = serviceServer.accept();
			System.out.println("Client connected");

			BufferedReader in = new BufferedReader(new InputStreamReader(
					clientSocket.getInputStream()));
			DataOutputStream out = new DataOutputStream(
					clientSocket.getOutputStream());

			try {
				new Service(in, out);
			} catch (SocketException e) {

			}
			in.close();
			out.close();
			clientSocket.close();
			System.out.println("Client disconnected");
		}
	}
}